#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

bool is_prime(int n) {
    if (n <= 1) return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

int english_to_number(const string& word) {
    unordered_map<string, int> num_dict = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    return num_dict.count(word) ? num_dict.at(word) : -1;
}

int nearest_prime(int num) {
    if (num < 2) return 2;
    int fup = num;
    int maks = fup;
    while (true) {
        if (is_prime(maks)) return maks;
        if (is_prime(fup)) return fup;
        maks--;
        fup++;
    }
}

int main() {
    string words[3], word1, word2, word3;
    for (int i = 0; i < 3; i++) {
        cin >> words[i];
    }
    int num = english_to_number(words[0]) * 100 + english_to_number(words[1]) * 10 + english_to_number(words[2]);
    if (num == -1 || num < 100 || num > 999) {
        cout << "Wrong input" << endl;
        return 1;
    if (word1 == "zero" || word2 == "zero" || word3 == "zero") {
        cout <<"Wrong input" << endl;
    }
    }
    cout << nearest_prime(num) << endl;
    return 0;
}
